package com.love.cloud.admin.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.love.cloud.admin.service.OnLineUserInfoService;
import com.love.cloud.common.core.constant.CacheConstants;
import com.love.cloud.common.core.util.RedisUtils;
import com.love.cloud.common.mybatis.util.PageUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hongdongqu
 */
@Service
public class OnLineUserInfoServiceImpl implements OnLineUserInfoService {
    @Resource
    private RedisUtils redisUtils;
    @Resource
    private PageUtils pageUtils;

    @Override
    public Object allOnLineUserInfo() {
        List<String> keys = redisUtils.scan(CacheConstants.ONLINE_USER_INFO + "*");
        return redisUtils.multiGet(keys);
    }

    @Override
    public Object allOnLineUserNum() {
        List<String> keys = redisUtils.scan(CacheConstants.ONLINE_USER_INFO + "*");
        return keys.size();
    }

    @Override
    public Object onlineUserPage() {
        Page page = pageUtils.page();
        List<String> keysForPage = redisUtils.findKeysForPage(CacheConstants.ONLINE_USER_INFO + "*", page.getCurrent(), page.getSize());
        page.setRecords(redisUtils.multiGet(keysForPage));
        return page;
    }
}
